package com.bjpowernode.mvc.convert;


import com.bjpowernode.db.result.BidResult;
import com.bjpowernode.mvc.model.dto.BidRankDTO;
import com.bjpowernode.mvc.model.vo.BidRankVO;
import com.bjpowernode.mvc.model.vo.BidVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;


import java.util.List;

@Mapper(componentModel = "spring")
public interface BidConvert {
    //1、 BidRankDTO -> BidRankVO
    @Mappings({
            @Mapping(target = "phone", source = "phone", qualifiedByName = "formatPhone")
    })
    BidRankVO toBidRankVO(BidRankDTO bidRankDTO);

    //2、List<BidRankVO> -> List<BidRankDTO>
    List<BidRankVO> toBidRankVo(List<BidRankDTO> bidRankDTOList);

    @Named("formatPhone")
    default String formatPhone(String phone) {
        String result;
        if (phone != null && phone.length() == 11) {
            result = phone.substring(0, 3) + "******" + phone.substring(9);
        } else {
            result = "_";
        }
        return result;
    }

    //3、BidResult -> BidVO
    @Mappings({
            @Mapping(target = "phone", source = "phone", qualifiedByName = "formatPhone"),
            @Mapping(target = "money", source = "bidMoney"),
            @Mapping(target = "bidTime", source = "bidTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    })
    BidVO toBidVO(BidResult bidResult);

    List<BidVO> toListBidVO(List<BidResult> bidResultList);


}
